package com.cooge.sharevideo.web.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooge.sharevideo.web.dao.EpisodeVideoDao;
import com.cooge.sharevideo.web.dao.MenuDao;
import com.cooge.sharevideo.web.dao.MenuEpisodeDao;
import com.cooge.sharevideo.web.pojo.EpisodeVideo;
import com.cooge.sharevideo.web.pojo.Menu;
import com.cooge.sharevideo.web.pojo.MenuEpisode;
import com.cooge.sharevideo.web.service.MenuService;
@Service
public class MenuServiceImpl implements MenuService {
	@Autowired
	MenuDao	 menuDao;
	@Autowired
	EpisodeVideoDao episodeVideoDao;
	@Autowired
	MenuEpisodeDao menuEpisodeDao;

	@Override
	public List<Menu> getList() {
		
		return menuDao.getlist();
	}

	@Override
	public Menu getMenuById(Long Id) {
		return menuDao.get(Id);
	}

	@Override
	public Menu getMenuByVideoId(Long videoId) {
		
		EpisodeVideo episodeVideo  = new EpisodeVideo();
		episodeVideo.setVideoId(videoId);
		episodeVideo = episodeVideoDao.getList(episodeVideo).get(0);
		MenuEpisode menuEpisode  = menuEpisodeDao.get(episodeVideo.getEpisodeId());
		Menu menu = menuDao.get(menuEpisode.getMenuId());
		
		return menu;
	}

	@Override
	public Menu getMenuByEpisodeId(Long episodeId) {
		
		MenuEpisode menuEpisode = new MenuEpisode();
		menuEpisode.setEpisodeId(episodeId);
		menuEpisode  = menuEpisodeDao.getList(menuEpisode).get(0);
		Menu menu = menuDao.get(menuEpisode.getMenuId());
		return menu;
	}

	@Override
	public List<Menu> getList(Menu menu) {
		return menuDao.getList(menu);
	}
}
